#-*- coding: utf-8 -*-
'''
Created on Aug 24, 2012

@author: bbg
'''

from sqlalchemy import Integer, Column, String, MetaData, Table,DateTime
from sqlalchemy.orm import mapper

class Stat_class_report(object):
    '''
       部门分析报表    
    '''
    
    _Mapper_ = None
    _company_id_ = -1    

    def __init__(self):
        self.uuid =''
        self.modify_time ='1999-09-09'
        self.stat_class_name =''
        self.sell_count =0
        self.amount =0
        self.discount =0
        self.after_discount =0
        self.sort_rank=0
    
    @staticmethod
    def doMapping(company_id):
        '''
                    按company_id分库，每次生成对象前都要执行一次，以便map到正确的数据库上去
        '''
        if Stat_class_report._company_id_ == company_id:
            return
                
        if Stat_class_report._Mapper_ is not None:
            Stat_class_report._Mapper_.dispose()
            
        metaData = MetaData()
        stat_class_reportTable = Table('stat_class_report', metaData,                                   
                           Column('uuid', String, primary_key = True),
                           Column('modify_time', DateTime),
                           Column('stat_class_name', String, primary_key = True),
                           Column('sell_count', Integer),
                           Column('amount', Integer),
                           Column('discount', Integer),
                           Column('after_discount', Integer),
                           Column('sort_rank', Integer),
                           schema = "report_%s" % company_id)
                
        Stat_class_report._Mapper_ = mapper(Stat_class_report, stat_class_reportTable)
        
